/**
 * 学习目标：React中常见的表单元素
 *
 */
import React from 'react';
import ReactDOM from 'react-dom';

class App extends React.Component {
  // 声明state
  // ins：快捷键
  state = {
    name: '',
    desc: '',
    city: '2',
    isSinge: false,
  };

  handleChangeName = (e) => {
    this.setState({ name: e.target.value });
  };

  handleChangeDesc = (e) => {
    this.setState({ desc: e.target.value });
  };

  handleChangeCity = (e) => {
    this.setState({ city: e.target.value });
  };

  handleChangeSingle = (e) => {
    this.setState({ isSinge: e.target.checked });
  };

  render() {
    // cs ：快捷键
    const { name, desc, city, isSinge } = this.state;
    return (
      <div>
        姓名：
        <input type="text" value={name} onChange={this.handleChangeName} />
        <br />
        描述：<textarea value={desc} onChange={this.handleChangeDesc}></textarea>
        <br />
        城市：
        <select value={city} onChange={this.handleChangeCity}>
          <option value="1">北京</option>
          <option value="2">上海</option>
          <option value="3">广州</option>
          <option value="4">深圳</option>
        </select>
        <br />
        {/* 🔔 checkbox它的值，是由checked属性控制 */}
        是否单身：
        <input type="checkbox" checked={isSinge} onChange={this.handleChangeSingle} />
      </div>
    );
  }
}
ReactDOM.render(<App></App>, document.getElementById('root'));
